#!/usr/bin/python

"""
On Error - it returns one of the following:
-1 forking error
2 bad usage
3 admin username/password error or network error
4 username doesn't exist
5 the prog does not have authentication
6 config file error
7 args too long
8 captcha error
42 other error
"""


import gdata.apps.service

def authuser(username, domain, password):
  print "HI I'm _in_ the machine"
  email = username + "@" + domain
  print email
  user = gdata.apps.service.AppsService(email=email, domain=domain, password=password)
  try:
    user.ProgrammaticLogin()
  except gdata.service.BadAuthentication:
    return 3
  except gdata.apps.service.AppsForYourDomainException:
    return 4
  except gdata.service.CaptchaRequired:
    return 8
  except:
    return 42
  #return 0 on success
  return 0  

if __name__ == "__main__":
  print "authing mctest bad pass", authuser("mctest", "coe.isu.edu", "bleh")
  print "authing unknown user", authuser("bleh", "coe", "bleh")
  print "authing good user", authuser("mctest", "coe.isu.edu", "pam_goog_so")
  print "authing bad user", authuser("mctest2", "coe.isu.edu", "pam_goog_so")

